﻿    @using eLoan.Models;
@model ChequeClearingModel

@{
    ViewBag.Title = "Cheque Clearing";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Cheque Clearing</h2>

        <ol class="breadcrumb">
            <li>
                Workspace
            </li>
            <li class="active">
                <strong>Cheque Clearing</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
            @using (Html.BeginForm("SaveChequeClearing", "Workspace", FormMethod.Post, new { id = "saveForm" }))
            {
    <fieldset>
        <div class="ibox-title">
            <div class="divSearch">
                <table class="table-search">
                    <tr>
                        <th>
                            <span>@Html.LabelFor(m => m.Branches)</span>
                        </th>
                        <th>
                            <span>@Html.LabelFor(m => m.Agents)</span>
                        </th>
                        <th>
                            <span>@Html.LabelFor(m => m.FromDate)</span>
                        </th>
                        <th>
                            <span>@Html.LabelFor(m => m.ToDate)</span>
                        </th>
                        <th colspan="4"></th>
                    </tr>
                    <tr>
                        <td>
                            @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "text-box single-line", @width = "50%", @onchange = "GetAgents();" })
                        </td>
                        <td style="padding-left:10px">
                            @Html.DropDownListFor(m => m.SelectedAgentID, Model.Agents, new { @id = "ddlAgents", @class = "text-box single-line", @width = "50%", @onchange = "Refresh()" })
                        </td>
                        <td style="padding-left:10px">
                            @Html.TextBoxFor(m => m.FromDate, "{0:MM/dd/yyyy}", new { @class = "form-control input datepicker" })
                        </td>
                        <td style="padding-left:10px">
                            @Html.TextBoxFor(m => m.ToDate, "{0:MM/dd/yyyy}", new { @class = "form-control input datepicker" })
                        </td>
                        <td style="vertical-align:bottom">
                            <button type="submit" id="btnSearch" class="btn btn-primary btnSearch" name="command" value="Refresh">Search</button>
                        </td>
                        <td style="vertical-align:bottom">
                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#confirm-cancel">Cancel</button>
                            <button type="submit" id="btnCancel" style="display:none" name="command" value="Cancel">Cancel</button>
                        </td>
                        <td style="vertical-align:bottom">
                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#confirm-dishonor">Dishonor</button>
                            <button type="submit" id="btnDishonor" style ="display:none" name="command" value="Dishonor">Dishonor</button>
                        </td>
                        <td class="align-right">
                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#confirm-clear">Clear</button>
                            <button type="submit" id="btnClear" style="display:none" name="command" value="Clear">Clear</button>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="ibox-content">
                <table id="tbl" class="table table-bordered table-List">
                    <thead>
                        <tr>
                            <th>Borrower</th>
                            <th>Loan Payment</th>
                            <th>Penalty</th>
                            <th>Date Posted</th>
                            <th>Status</th>
                            <th>Remarks</th>
                            <th>
                                @Html.CheckBox("chkCheckAll", false, new { @class = "checkAll", @onchange = "checkAll(this)" })
                            </th>
                        </tr>
                    </thead>
                    <tbody id="tableBody">
                        @for (var i = 0; i < Model.Items.Count(); i++)
                        {
                        <tr class="trData">
                            <td>
                                @Html.HiddenFor(m => m.Items[i].ID)
                                @Html.DisplayFor(m => m.Items[i].BorrowerName)
                            </td>
                            <td style="text-align:right">
                                @Html.ValueFor(m => m.Items[i].Amount, "{0:#,###,##0.00}")
                            </td>
                            <td style="text-align:right">
                                @Html.ValueFor(m => m.Items[i].Penalty, "{0:#,###,##0.00}")
                            </td>
                            <td>
                                @Html.ValueFor(m => m.Items[i].DatePosted, "{0:MM/dd/yyyy}")
                            </td>
                            <td>
                                @Html.HiddenFor(m => m.Items[i].StatusID)
                                @Html.DisplayFor(m => m.Items[i].Status)
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.Items[i].Remarks, new { @class="single-line" })
                            </td>
                            <td>
                                @Html.CheckBoxFor(m => m.Items[i].IsSelected, new { @id = "chk_" + Model.Items[i].ID, @class = "check", @onchange = "checkMe();" })
                            </td>
                        </tr>
                        }
                    </tbody>
                </table>

            <div class="modal fade" id="confirm-cancel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">

                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">Confirmation</h4>
                        </div>

                        <div class="modal-body">
                            <p>Are you sure you want to cancel the selected items?</p>
                            <p class="debug-url"></p>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                            <button type="button" class="btn btn-primary btn-ok" data-dismiss="modal">Yes</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="confirm-dishonor" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">

                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">Confirmation</h4>
                        </div>

                        <div class="modal-body">
                            <p>Are you sure you want to dishonor the selected items?</p>
                            <p class="debug-url"></p>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                            <button type="button" class="btn btn-primary btn-ok" data-dismiss="modal">Yes</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="confirm-clear" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">

                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">Confirmation</h4>
                        </div>

                        <div class="modal-body">
                            <p>Are you sure you want to clear the selected items?</p>
                            <p class="debug-url"></p>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                            <button type="button" class="btn btn-primary btn-ok" data-dismiss="modal">Yes</button>
                        </div>
                    </div>
                </div>
            </div>

            <button type="submit" id="btnRefresh" style="display:none" name="command" value="Refresh">Refresh</button>

        </div>
    </fieldset>
            }
            </div>

        </div>
    </div>
</div>

@section Styles {
@Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
@Styles.Render("~/plugins/dataPickerStyles")
    <style>

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search th {
            width: 250px;
        }

            .table-search th label {
                margin-top: 15px;
                margin-left: 20px;
            }

            .table-search th .span {
                padding-left: 10px;
            }

        .table-search .align-right{
            text-align: right;
        }

            .table-search td select {
                margin-left: 15px !important;
                margin-bottom: 10px !important;
            }

            .table-search td input {
                margin-left: 25px !important;
                margin-bottom: 10px !important;
            }

            .table-search td button {
                margin-right: 15px;
                margin-bottom: 10px !important;
            }

        .table-search td .btnSearch {
            margin-bottom: 0px;
            margin-left: 40px !important;
        }

    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
    }

</style>

}

@section Scripts {
@Scripts.Render("~/plugins/dataTables")
@Scripts.Render("~/plugins/dataPicker")

<script type="text/javascript">

    $(document).ready(function () {

        $('.table-List').dataTable({
            ordering: true,
            searching: false,
            paging: false,
            scrollY: 400,
            scrollX: true
        });
        
        $(window).keydown(function (event) {
            if (event.keyCode == 13) {
                Refresh();
                return false;
            }
        });

        $('#confirm-cancel').on('click', '.btn-ok', function (e) {
            document.getElementById('btnCancel').click();
        });

        $('#confirm-dishonor').on('click', '.btn-ok', function (e) {
            document.getElementById('btnDishonor').click();
        });

        $('#confirm-clear').on('click', '.btn-ok', function (e) {
            document.getElementById('btnClear').click();
        });

        $('.datepicker').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            format: 'mm/dd/yyyy',
            autoclose: true

        });

        SetDateFormat();
    });

    function Refresh() {
        document.getElementById('btnRefresh').click();
    }

    function GetAgents()
    {
        var val = $('#ddlBranches').val();
        var subItems = "";

        $.getJSON("@Url.Action("GetAgents","Borrower")", { branchCode: val },
        function (data) {

            subItems += "<option value='0'>All</option>"
            $.each(data, function (index, item) {
                subItems += "<option value='" + $.trim(item.Value) + "'>" + $.trim(item.Text) + "</option>"
            });

            $("#ddlAgents").html(subItems)
    });
    }

    function SetDateFormat() {

        $('#pd .input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            format: 'mm/dd/yyyy',
            autoclose: true

        });

        var pd = $('#txtPaymentDate').val();
        $('#pd .input-group.date').datepicker("update", new Date(pd));

    }

    function checkAll(me) {
        var val = $(me).is(':checked');

        $('.check').each(function () {

            var disabled = $(this).is(':disabled');
            if (!disabled)
                $(this).prop('checked', val);
        });

        $('.prnt').each(function () {

            if (val) {
                $(this).removeAttr('disabled');
            }
            else {
                $(this).attr('disabled', 'disabled');
            }

        });


    }

    function checkMe() {
        var allIsChecked = true;

        $('.check').each(function () {
            var val = $(this).is(':checked');

            if (!val)
                allIsChecked = false;

        });

        $('#chkCheckAll').prop('checked', allIsChecked);

    }

</script>

}
